package com.example.demo.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class MyController {
    @GetMapping("/test")
    public ResponseEntity<String> testMethod() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("查询数据阶段");
        // 模拟查询数据库操作，这里替换为真实的数据库查询逻辑
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stopWatch.stop();

        stopWatch.start("数据处理阶段");
        // 模拟数据处理操作
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stopWatch.stop();

        System.out.println(stopWatch.prettyPrint());

        return ResponseEntity.ok("操作完成，耗时情况如下：\n" + stopWatch.prettyPrint());
    }
}